<template>
	<div id='system' v-loading="loading">
		<div class="content-top">
			<span class="h1">查询分析</span>
			<span class="h2">推广明细查询</span>
		</div>
		<div class="top-btn clearfix">
			<div class="left-content">
				<span class="tip">推广明细查询分析表</span>
			</div>
			<div style="float:left">
				<span class="demonstration" style="margin-left: 15px;">开始日期</span>
				<el-date-picker v-model="starTime" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
				</el-date-picker>
				<span class="demonstration">结束日期</span>
				<el-date-picker v-model="endTime" type="date" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
				</el-date-picker>
			</div>
			<div class="right-search1">
				<el-input v-model="input" placeholder="输入关键词…"></el-input>
				<el-button type="primary" @click="look()" style="margin-left: 10px;">查看</el-button>
				<el-button type="primary" @click="excel()">导出excel</el-button>
			</div>
		</div>
		<el-table :data="tableData" style="width: 100%">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="POPPara" label="推广参数">
			</el-table-column>
			<el-table-column prop="IP" label="IP地址">
			</el-table-column>
			<el-table-column prop="TimeStr" label="时间">
			</el-table-column>
		</el-table>
		<div class="pages">
			<el-pagination small :current-page="index" @current-change="handleCurrentChange" layout="prev, pager, next" :total="total" background prev-text='上一页' next-text='下一页'>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	import api from '../../../api/api'
	export default {
		name: 'popdetail',
		data() {
			return {
				index:1,
				total:1,
				loading:true,
				starTime: new Date(), //开始日期
				endTime: new Date(), //结束日期
				input: '', //搜索
				tableData: [],
			}
		},
		created() {
			this.getpopdetail(this.index)
		},
		methods: {
			excel(){
				this.$axios.post(api.getpopdetail, {
					"SDate": this.starTime,
					"EDate": this.endTime,
					"PagePara": {
						"Para": this.input,
						"PageSize": 10,
						"PageIndex": this.index - 1,
						"OrderbyString": "RegTotal",
						 "ToExcel": true
					}
				}).then(res => {
					if(res.data.isOK){
						if(res.data.data.ExcelResult && res.data.data.ExcelResult.isOK) {

							this.loading = false
							var urls = res.data.data.ExcelResult.data.filePath
							window.location.href = api.host+'/template/'+urls
						} else{
							this.loading = false
							this.$message.error(res.data.data.ExcelResult.msg);
						}
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			},
			handleCurrentChange(val) {
				this.index = val
				this.getpopdetail(this.index)
			},
			look() {
				this.index = 1
				this.getpopdetail(this.index)
			},
			getpopdetail(val) {
				this.$axios.post(api.getpopdetail, {
					"SDate": this.starTime,
					"EDate": this.endTime,
					"PagePara": {
						"Para": this.input,
						"PageSize": 10,
						"PageIndex": val - 1,
						"OrderbyString": "RegTotal",
						"ToExcel": false
					}
				}).then(res => {
					if(res.data.isOK) {
						this.loading = false
						this.tableData = res.data.data.Data
						this.total = res.data.data.Items ? res.data.data.Items : 1
					} else {
						if(res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
							this.$router.push({
								path: '/admin'
							})
						} else {
							this.loading = false
							this.$message.error(res.data.msg);
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>